<title>交易单</title>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="financial-trade-index-search_from">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">交易单号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="trade_no" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-inline">
                        <script type="text/html" template lay-url="{{ layui.setter.apiHost }}/financial/trade/get_type" lay-done="layui.form.render();">
                            <select name="type">
                                <option value=""></option>
                                {{# layui.each(d.data, function(index, item){ }}
                                <option value="{{ index }}">{{ item }}</option>
                                {{# }); }}
                            </select>
                        </script>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="financial-trade-index-search_button">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="financial-trade-index" lay-filter="financial-trade-index"></table>
            <script type="text/html" id="financial-trade-index-flag_tmp">
                {{# if(d.flag == 1){ }}
                <span class="layui-badge">风险</span>
                {{# } else { }}
                <span class="layui-badge layui-bg-green">正常</span>
                {{# } }}
            </script>
        </div>
    </div>
</div>
<script>
    layui.use(['common', 'table'], function () {
        var $ = layui.jquery,
            common = layui.common,
            view = layui.view,
            table = layui.table,
            form = layui.form,
            lay_id_prefix = 'financial-trade-index',//当前页id前缀
            api_action_url = layui.setter.apiHost + '/financial/trade';

        //表单搜索
        form.on('submit(' + lay_id_prefix + '-search_button)', function (data) {
            var field = data.field;
            field.page = 1;//默认第一页
            table.reload(lay_id_prefix, {
                where: field
            });
        });

        //表格操作
        table.render({
            elem: '#' + lay_id_prefix,
            url: api_action_url,
            toolbar: '#' + lay_id_prefix + '-toolbar_tmp',
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field: 'id', title: 'ID', width: 80},
                {field: 'trade_no', title: '交易单号', minWidth: 200},
                {field: 'username', title: '用户名', width: 120},
                {field: 'type', title: '交易类型', width: 100},
                {field: 'subtotal', title: '金额', width: 100},
                {field: 'pay_total', title: '支付金额', width: 100},
                {field: 'payment', title: '支付方式', width: 100},
                {field: 'pay_at', title: '支付时间', width: 170},
                {field: 'payment_no', title: '第三方单号', width: 170},
                {field: 'flag', title: '风险单', width: 80, fixed: 'right', templet: '#' + lay_id_prefix + '-flag_tmp'}
            ]],
            page: true
        });
    });
</script>